package org.argus.management.system.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.argus.management.domain.Domain;
import org.argus.management.system.model.DomainSearchReq;
import org.argus.management.system.service.DomainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.argus.common.core.domain.R;

import javax.validation.Valid;

/**
 * @Author 刘文/Cliff Liu
 * @Date 2024/5/10
 */
@RestController
@RequestMapping("/system/v1/domain")
public class DomainController {

    @Autowired
    private DomainService domainService;

    @GetMapping("/user-domains")
    public R<List<Domain>> getUserDomains() {
        return R.ok(domainService.getUserDomains());
    }

    @GetMapping("/all-domains")
    public R<List<Domain>> getAllDomains() {
        return R.ok(domainService.getAllDomains());
    }

    @GetMapping("/user-domain-ids/{userId}")
    public R<List<Long>> getUserDomainIds(@PathVariable("userId") Long userId) {
        return R.ok(domainService.getUserDomainIds(userId));
    }

    @PostMapping("/save")
    public R<Void> save(@RequestBody @Valid Domain domain) {
        domainService.save(domain);
        return R.ok();
    }

    @DeleteMapping("/{id}")
    public R<Void> delete(@PathVariable("id") Long id) {
        domainService.delete(id);
        return R.ok();
    }

    @ApiOperation("业务域分页查询")
    @GetMapping("/page")
    public R<Page<Domain>> page(DomainSearchReq searchReq, Page page) {
        return R.ok(domainService.page(searchReq, page));
    }
}
